package com.lyh.crm.workbench.service.impl;

import com.lyh.crm.settings.dao.UserDao;
import com.lyh.crm.settings.domain.User;
import com.lyh.crm.utils.SqlSessionUtil;
import com.lyh.crm.vo.PaginationVO;
import com.lyh.crm.workbench.dao.ActivityDao;
import com.lyh.crm.workbench.dao.ActivityRemarkDao;
import com.lyh.crm.workbench.dao.ProductDao;
import com.lyh.crm.workbench.domain.Activity;
import com.lyh.crm.workbench.domain.ActivityRemark;
import com.lyh.crm.workbench.domain.Product;
import com.lyh.crm.workbench.service.ActivityService;
import com.lyh.crm.workbench.service.ProductService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ProductServiceImpl implements ProductService {

    private ProductDao productDao = SqlSessionUtil.getSqlSession().getMapper(ProductDao.class);

    private UserDao userDao = SqlSessionUtil.getSqlSession().getMapper(UserDao.class);


    public PaginationVO<Product> pageList(Map<String, Object> map) {
        //取得total
        int total = productDao.getTotalByCondition(map);
        //取得dataList
        List<Product> dataList = productDao.getProductListByCondition(map);

        //创建一个vo对象，将total和dataList封装到vo中
        PaginationVO<Product> vo = new PaginationVO<Product>();
        vo.setTotal(total);
        vo.setDataList(dataList);

        //将vo返回
        return vo;
    }

    public boolean save(Product p) {
        boolean flag = true;

        int count = productDao.save(p);
        if(count!=1){

            flag = false;

        }

        return flag;
    }

    public boolean delete(String[] ids) {
        boolean flag = true;

        //删除市场活动
        int count = productDao.delete(ids);
        if(count!=ids.length){

            flag = false;

        }

        return flag;
    }

    public Map<String, Object> getProduct(String id) {

        //取a
        Product a = productDao.getById(id);

        //将uList和a打包到map中
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("a", a);

        //返回map就可以了
        return map;
    }

    public boolean update(Product p) {
        boolean flag = true;

        int count = productDao.update(p);
        if(count!=1){

            flag = false;

        }

        return flag;
    }
}






















